<template>
    <div class="modal">
        <h3>{{ title }}</h3>
        <button class="modal-btn" @click="modalShow = true">打开弹窗</button>
        <teleport to="body">
            <div class="modal-bg" v-if="modalShow">
                <div class="modal-box">
                    <span class="modal-close-btn" @click="modalShow = false">x</span>
                    <div class="modal-content">
                        <p>我是一个弹窗</p>
                    </div>
                </div>
            </div>
        </teleport>
    </div>
</template>

<script>
export default {
    props: {
        title: {
            type: String,
            default: ''
        },
    },
    data() {
        return {
            modalShow: false
        }
    },
}
</script>

<style lang="scss" scoped>
.modal-bg {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-color: rgba($color: #000000, $alpha: 0.4);
    .modal-box {
        position: absolute;
        left: 50%;
        top: 50%;
        width: 40%;
        height: 300px;
        background-color: #fff;
        border-radius: 10px;
        transform: translate(-50%, -50%);

        .modal-close-btn {
            position: absolute;
            top: 0;
            right: 0;
            width: 50px;
            line-height: 50px;
            font-size: 20px;
            text-align: center;
            cursor: pointer;
        }

        .modal-content {
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    }
}
</style>